package top.zy.service.zymallgoodsservice.goods.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import top.zy.common.zymallcommon.vo.PageResult;
import top.zy.service.zymallgoodsinterface.dto.GoodsPageParam;
import top.zy.service.zymallgoodsinterface.dto.GoodsParams;
import top.zy.service.zymallgoodsinterface.dto.SpuParam;
import top.zy.service.zymallgoodsinterface.entity.Sku;
import top.zy.service.zymallgoodsinterface.entity.Spu;
import top.zy.service.zymallgoodsinterface.entity.SpuDetail;
import top.zy.service.zymallgoodsinterface.vo.GoodsVo;
import top.zy.service.zymallgoodsinterface.vo.SkuVo;
import top.zy.service.zymallgoodsservice.goods.service.GoodsService;

import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 15:50 2019/6/25
 */
@RestController
public class GoodsController {
    @Autowired
    @Qualifier("goodsServiceImpl")
    private GoodsService goodsService;

    /***
     * 根据spuId查询spu
     * @param id
     * @return
     */
    @GetMapping("spu/{id}")
    GoodsVo querySpuBySpuId(@PathVariable("id")Long id){
        return goodsService.querySpuBySpuId(id);
    }

    /**
     * 分页查询spu信息
     * @param goodsPageParam
     * @return
     */
    @GetMapping("spu/page")
    public PageResult<GoodsVo> queryGoodsPage(GoodsPageParam goodsPageParam){
       return goodsService.queryGoodsPage(goodsPageParam);
    }

    /**
     *上下架商品
     * @param spuParam
     */
    @PutMapping("spu/saleable")
    public void saleableGoods(@RequestBody SpuParam spuParam){
     goodsService.saleableGoods(spuParam);
    }

    /**
     *删除商品信息
     * @param id
     */
    @DeleteMapping("delete/{id}")
    public void deleteGoods(@PathVariable("id") Long id){
     goodsService.deleteGoods(id);
    }

    /***
     *新增商品信息
     * @param goodsParams
     */
    @PostMapping("add")
    public void saveGoods(@RequestBody GoodsParams goodsParams){
     goodsService.saveGoods(goodsParams);
    }

    /**
     * 根据id查询spu详情
     * @param id
     * @return
     */
    @GetMapping("spu/detail/{id}")
    public SpuDetail querySpuDetailById(@PathVariable("id") Long id){
     return goodsService.querySpuDetailById(id);
    }

    /***
     * 根据spuId查询sku集合
     * @param id
     * @return
     */
    @GetMapping("sku/list/{id}")
    public List<SkuVo> querySkuBySpuId(@PathVariable("id") Long id){
      return  goodsService.querySkuBySpuId(id);
    }

    /***
     * 更新商品
     * @param goodsParams
     */
     @PutMapping("update")
    public void updateGoods(@RequestBody GoodsParams goodsParams){
      goodsService.updateGoods(goodsParams);
    }


}
